import Vue from 'vue'
import App from './App.vue'
import VueRouter from "vue-router";
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import iView from 'iview';
import 'iview/dist/styles/iview.css';
import Header from './components/Header'
import Footer from './components/Footer'
import Slide from './components/Slide'
import axios from 'axios'
axios.defaults.withCredentials = true;
import store from './vuex/store'
Vue.prototype.http = axios;
Vue.config.debug = true;
Vue.use(Header)
Vue.use(Footer)
Vue.use(Slide)
Vue.use(ElementUI)
Vue.use(iView)

import routers from './router/router'
Vue.use(VueRouter);

import mock from './data/mock'
mock.analog()

const router = new VueRouter({
    mode: 'history',
    base: __dirname,
    routes: routers,
    scrollBehavior: () => { return false }
})
router.afterEach(function (from, to) {
    //判断是否登录
    // console.log(from.path.split('/')[1]);

    if (from.path.split('/')[1] == 'donation') {
        if (store.state.isLogined.toString() == true.toString()) {
            next()
        } else {
            router.push('/login')
        }
    }

    if (from.path.split('/')[1] == 'idea') {
        console.log(store.state.isLogined);
        if (store.state.isLogined.toString() == true.toString()) {
            next()
        } else {
            router.push('/login')
        }
    }

    if (from.path.split('/')[1] == 'my') {
        if (store.state.isLogined.toString() == true.toString()) {
            next()
        } else {
            router.push('/login')
        }
    }

    if (from.path.split('/')[1] == 'rank') {
        if (store.state.isLogined.toString() == true.toString()) {
            next()
        } else {
            router.push('/login')
        }
    }

    if (to.path.split('/')[1] == 'admin') {
       store.state.isShow=true;
    }
    if (from.path.split('/')[1] == 'home') {
        store.state.isShow=false;
    }
});
new Vue({
    el: '#app',
    router,
    store,
    render: h => h(App)
})
